var FeaturesAnimation = EventDispatcher.extend({
    panel: null,
    isHeightChanged: false,
    page: null,
        
    constructor: function(panel)
    {
        this.panel = panel;
        this.duration = 'fast';
    },
    
    // fade out Panel content, then close panel
    closePanel: function()
    {
        this.panel.children().animate({opacity: 0}, this.duration, handler(this, "slideUpPanel"));
    },
    
    // close panel
    slideUpPanel: function()
    {
        this.panel.slideUp(this.duration, handler(this, "onPanelClose"));
    },
    
    onPanelClose: function()
    {
        this.dispatchEvent('panelClosed');
    },
    
    // reset content opacity, then increase panel height
    slideDownPanel: function()
    {   
        this.panel.children().css({opacity: 0});        
        this.updatePanelHeight(0);
    },
    
    // todo: split function ?
    updatePanelHeight: function(startHeight)
    {  
        this.panel.css({height: "auto"});        
        var newPanelHeight = this.panel.height();   
                
        startHeight += "px";
        this.panel.css({height: startHeight});
        
        newPanelHeight = newPanelHeight + "px";
        this.panel.animate({height: newPanelHeight}, this.duration, handler(this, "fadeInPanelContent"));
    },
    
    
    // fade in panel content
    fadeInPanelContent: function()
    {
        this.panel.children().animate({opacity: 1}, this.duration);
    },
    
    // fade out current panel content, then show new content
    changeContent: function()
    {
        this.isHeightChanged = false;
        this.panel.children().animate({opacity: 0}, this.duration, handler(this, "showNewContent"));
    },
    
    showNewContent: function()
    {   
        if(!this.isHeightChanged)
        {
            this.dispatchEvent("contentFaded");
            
            // refresh panel height
            var currHeight = this.panel.height();            
            this.updatePanelHeight(currHeight);
            this.isHeightChanged = true;
        }
    }
});  